﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Xinyi.Common;
using Xinyi.Data;

namespace yfjs
{
    public partial class GetData : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BindData();
        }

        /// <summary>
        /// 绑定数据
        /// </summary>
        private void BindData()
        {
            string strType, strID, strTypeID, strSql, strResult, strUrl;

            //获取参数
            strType = Request.QueryString["type"];
            strTypeID = Request.QueryString["typeid"];
            strID = Request.QueryString["id"];
            strUrl = Request.QueryString["url"];
            strSql = "";
            strResult = "";

            //判断参数是否为空
            if (strType == null)
            {
                Response.Write("document.write('');");
                Response.End();
            }

            //打开数据库链接
            DataClass myData = new DataClass();
            SqlConnection myConn = myData.ConnOpen();

            //判断用户是否登录
            if (strType == "checkuserlogin")
            {
                //判断用户是否登录
                if (Session["UserID"] != null)
                {
                    strResult = "<script>window.location.href='user_info.aspx';</script>";
                }
            }

            //判断新闻
            if (strType == "newprev")
            {
                //判断是否获取一条新闻数据
                if (FunctionClass.CheckStr(strID, 1) && FunctionClass.CheckStr(strTypeID, 1))
                {
                    strSql = "select * from T_News where IsShow=1 and NewType=" + strTypeID + " order by sid,id desc";

                    DataSet myDs = myData.GetDataSet(strSql, myConn);
                    for (int i = 0; i < myDs.Tables[0].Rows.Count; i++)
                    {
                        if (myDs.Tables[0].Rows[i]["ID"].ToString() == strID)
                        {
                            if (i > 0)
                                strResult = "<a href='newinfo_" + myDs.Tables[0].Rows[i - 1]["ID"].ToString() + ".html'>上一篇：" + myDs.Tables[0].Rows[i - 1]["Title"].ToString() + "</a>";
                            else
                                strResult = "上一篇：没有了！";
                        }
                    }
                    myDs.Dispose();
                }
            }

            //判断新闻
            if (strType == "newnext")
            {
                //判断是否获取一条新闻数据
                if (FunctionClass.CheckStr(strID, 1) && FunctionClass.CheckStr(strTypeID, 1))
                {
                    strSql = "select * from T_News where IsShow=1 and NewType=" + strTypeID + " order by sid,id desc";

                    DataSet myDs = myData.GetDataSet(strSql, myConn);
                    for (int i = 0; i < myDs.Tables[0].Rows.Count; i++)
                    {
                        if (myDs.Tables[0].Rows[i]["ID"].ToString() == strID)
                        {
                            if (i + 1 < myDs.Tables[0].Rows.Count)
                                strResult = "<a href='newinfo_" + myDs.Tables[0].Rows[i + 1]["ID"].ToString() + ".html'>下一篇：" + myDs.Tables[0].Rows[i + 1]["Title"].ToString() + "</a>";
                            else
                                strResult = "下一篇：没有了！";
                        }
                    }
                    myDs.Dispose();
                }
            }

            //判断新闻
            if (strType == "video")
            {
                //<img src="images/tubiao_04.jpg" width="19" height="10" align="absmiddle" /> 视频：$title$<br />
                if (FunctionClass.CheckStr(strID, 1) && FunctionClass.CheckStr(strTypeID, 1))
                {
                    strSql = "select top 8 * from T_News where NewType=3 and IsShow=1 and IsRecommend=1 order by sid,id";

                    DataSet myDs = myData.GetDataSet(strSql, myConn);

                    strResult = "";

                    if (strID == "1")//前4条
                    {
                        for (int i = 0; i < 4; i++)
                        {
                            if (i < myDs.Tables[0].Rows.Count)
                                strResult += "<div class=\"rvideo_1\"><a href=\"videoinfo_" + myDs.Tables[0].Rows[i]["ID"].ToString()
                                    + ".html\" target='_blank'><img src=\"images/tubiao_04.jpg\" width=\"19\" height=\"10\" align=\"absmiddle\" /> "
                                    + "" + myDs.Tables[0].Rows[i]["Title"].ToString() + "</a></div>";
                        }
                    }
                    else//后4条
                    {
                        for (int i = 4; i < 8; i++)
                        {
                            if (i < myDs.Tables[0].Rows.Count)
                                strResult += "<div class=\"rvideo_1\"><a href=\"videoinfo_" + myDs.Tables[0].Rows[i]["ID"].ToString()
                                    + ".html\" target='_blank'><img src=\"images/tubiao_04.jpg\" width=\"19\" height=\"10\" align=\"absmiddle\" /> "
                                    + "" + myDs.Tables[0].Rows[i]["Title"].ToString() + "</a></div>";
                        }
                    }

                    myDs.Dispose();
                }
            }

            //销量产品
            if (strType == "salenum")
            {
                if (FunctionClass.CheckStr(strID, 1))
                {
                    strSql = "select top " + strID + " * from T_Products where isShow=1 order by SaleNum desc,SID,ID desc";

                    DataSet myDs = myData.GetDataSet(strSql, myConn);
                    for (int i = 0; i < myDs.Tables[0].Rows.Count; i++)
                    {
                        if (i < myDs.Tables[0].Rows.Count - 1)
                            strResult += "<li><a href=\"proinfo_" + myDs.Tables[0].Rows[i]["ID"].ToString() + ".html\"><img src=\"" + myDs.Tables[0].Rows[i]["ProPic"].ToString()
                                + "\" /></a><br /><a href=\"proinfo_" + myDs.Tables[0].Rows[i]["ID"].ToString() + ".html\">" + myDs.Tables[0].Rows[i]["ProTip"].ToString()
                                + "</a><br /><span>￥" + myDs.Tables[0].Rows[i]["Price1"].ToString() + "</span></li>";
                        else
                            strResult += "<li style=\"border-bottom:0px;\"><a href=\"proinfo_" + myDs.Tables[0].Rows[i]["ID"].ToString()
                                + ".html\"><img src=\"" + myDs.Tables[0].Rows[i]["ProPic"].ToString()
                                + "\" /></a><br /><a href=\"proinfo_" + myDs.Tables[0].Rows[i]["ID"].ToString() + ".html\">" + myDs.Tables[0].Rows[i]["ProTip"].ToString()
                                + "</a><br /><span>￥" + myDs.Tables[0].Rows[i]["Price1"].ToString() + "</span></li>";
                    }
                    myDs.Dispose();
                }
            }

            //看过商品
            if (strType == "viewpro")
            {
                //判断是否有浏览记录了
                if (Session["ViewProInfo"] != null)
                {
                    FunctionClass myFun = new FunctionClass();
                    string strIDSql = myFun.GetIDSql(Session["ViewProInfo"].ToString(), '|', "ID");//获取sql条件语句

                    //判断条件是否存在
                    if (strIDSql != "")
                    {
                        strSql = "select * from T_Products where isShow=1 and (" + strIDSql + ") order by SID,ID desc";
                    }
                    else
                        strSql = "select top 10 * from T_Products where isShow=1 order by SID,ID desc";
                }
                else
                    strSql = "select top 10 * from T_Products where isShow=1 order by SID,ID desc";

                strResult += "<ul>";

                DataSet myDs = myData.GetDataSet(strSql, myConn);
                for (int i = 0; i < myDs.Tables[0].Rows.Count; i++)
                {
                    strResult += "<li><a href=\"proinfo_" + myDs.Tables[0].Rows[i]["ID"].ToString() + ".html\" title=\"" +
                        myDs.Tables[0].Rows[i]["ProName"].ToString() + "\"><img src=\"" +
                        myDs.Tables[0].Rows[i]["ProPic"].ToString() + "\" width=\"180\" height=\"125\" broder=\"0\" /></a></li>";
                }
                myDs.Dispose();

                strResult += "</ul>";
            }

            //显示产品窗口
            if (strType == "showwindows")
            {
                strSql = "select * from T_Products where IsShow=1 order by id";
                SqlDataReader myDr = myData.GetSqlDataReader(strSql, myConn);
                while (myDr.Read())
                {
                    //strResult += "<div id='xx" + myDr["ID"].ToString()
                    //    + "' class='pro_5' onmouseover=\"xxlb('xx" + myDr["ID"].ToString() + "','1',null,0)\" onmouseout=\"xxlb('xx"
                    //    + myDr["ID"].ToString() + "','0',null,1)\" ><div style='height:72px; overflow:hidden;'>"
                    //    + "<div class='pro_6'>" + myDr["ProName"].ToString() + "</div>"
                    //    + "<div style='padding-left:54px; color:#b5b5b5;'>" + FunctionClass.WriteHtml(myDr["ProTip"].ToString().Replace("\r\n","&nbsp;")) + "</div>"
                    //    + "</div><div style='text-align:right; padding-right:20px;'>"
                    //    + "<a style='color:#cfa972;' href='proinfo_" + myDr["ID"].ToString() + ".html' target='_blank'>更多详情 "
                    //    + "<img src='images/pro_10.jpg' align='absmiddle' border='0' /></a></div></div>";
                    strResult += "<div id='xx" + myDr["ID"].ToString()
                        + "' class='pro_5' onmouseover=\"xxlb('xx" + myDr["ID"].ToString() + "','1',null,0)\" onmouseout=\"xxlb('xx"
                        + myDr["ID"].ToString() + "','0',null,1)\" ><div style='height:24px; overflow:hidden;'>"
                        + "<div class='pro_6'>" + myDr["ProName"].ToString() + "</div>"
                        + "</div></div>";
                }
                myDr.Close();
                myDr.Dispose();
            }

            //显示产品窗口
            if (strType == "nextnews")
            {
                if (FunctionClass.CheckStr(strID, 1) && FunctionClass.CheckStr(strTypeID, 1))
                {
                    if (strTypeID == "0" || strTypeID == "")
                    { }
                    else
                    {
                        if (!FunctionClass.CheckStr(strUrl, 0))
                            strUrl = "newinfo";

                        string strText1, strText2;

                        DataSet myDs = myData.GetDataSet("select * from T_News where NewType=" + strTypeID + " order by sid,id desc", myConn);
                        int intCurr = 0;

                        for (int i = 0; i < myDs.Tables[0].Rows.Count; i++)
                        {
                            if (myDs.Tables[0].Rows[i]["ID"].ToString() == strID)
                            {
                                intCurr = i;
                                break;
                            }
                        }

                        if (intCurr - 1 < 0)
                            strText1 = "·前一篇：没有了！";
                        else
                            strText1 = "<a href=\""+strUrl+"_" + myDs.Tables[0].Rows[intCurr - 1]["ID"].ToString() + ".html\">前一篇：" + myDs.Tables[0].Rows[intCurr - 1]["Title"].ToString() + "</a>";
                        if (intCurr + 1 >= myDs.Tables[0].Rows.Count)
                            strText2 = "·后一篇：没有了！";
                        else
                            strText2 = "<a href=\""+strUrl+"_" + myDs.Tables[0].Rows[intCurr + 1]["ID"].ToString() + ".html\">后一篇：" + myDs.Tables[0].Rows[intCurr + 1]["Title"].ToString() + "</a>";

                        myDs.Dispose();

                        strResult = strText1 + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + strText2;
                    }
                }
            }

            //显示产品窗口
            if (strType == "nextnewsen")
            {
                if (FunctionClass.CheckStr(strID, 1) && FunctionClass.CheckStr(strTypeID, 1))
                {
                    if (strTypeID == "0" || strTypeID == "")
                    { }
                    else
                    {
                        if (!FunctionClass.CheckStr(strUrl, 0))
                            strUrl = "newinfo";

                        string strText1, strText2;

                        DataSet myDs = myData.GetDataSet("select * from T_News where NewType=" + strTypeID + " order by sid,id desc", myConn);
                        int intCurr = 0;

                        for (int i = 0; i < myDs.Tables[0].Rows.Count; i++)
                        {
                            if (myDs.Tables[0].Rows[i]["ID"].ToString() == strID)
                            {
                                intCurr = i;
                                break;
                            }
                        }

                        if (intCurr - 1 < 0)
                            strText1 = "·Previous：null!";
                        else
                            strText1 = "<a href=\""+strUrl+"_" + myDs.Tables[0].Rows[intCurr - 1]["ID"].ToString() + ".html\">Previous：" + myDs.Tables[0].Rows[intCurr - 1]["Title"].ToString() + "</a>";
                        if (intCurr + 1 >= myDs.Tables[0].Rows.Count)
                            strText2 = "·Next：null!";
                        else
                            strText2 = "<a href=\""+strUrl+"_" + myDs.Tables[0].Rows[intCurr + 1]["ID"].ToString() + ".html\">Next：" + myDs.Tables[0].Rows[intCurr + 1]["Title"].ToString() + "</a>";

                        myDs.Dispose();

                        strResult = strText1 + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + strText2;
                    }
                }
            }

            //显示产品窗口
            if (strType == "nextpro")
            {
                if (FunctionClass.CheckStr(strID, 1) && FunctionClass.CheckStr(strTypeID, 1))
                {
                    if (strTypeID == "0" || strTypeID == "")
                    { }
                    else
                    {
                        string strText1, strText2;

                        DataSet myDs = myData.GetDataSet("select * from T_Products where TypeID=" + strTypeID + " order by sid,id desc", myConn);
                        int intCurr = 0;

                        for (int i = 0; i < myDs.Tables[0].Rows.Count; i++)
                        {
                            if (myDs.Tables[0].Rows[i]["ID"].ToString() == strID)
                            {
                                intCurr = i;
                                break;
                            }
                        }

                        if (intCurr - 1 < 0)
                            strText1 = "·前一篇：没有了！";
                        else
                            strText1 = "<a href=\"proinfo_" + myDs.Tables[0].Rows[intCurr - 1]["ID"].ToString() + ".html\">前一篇：" + myDs.Tables[0].Rows[intCurr - 1]["ProName"].ToString() + "</a>";
                        if (intCurr + 1 >= myDs.Tables[0].Rows.Count)
                            strText2 = "·后一篇：没有了！";
                        else
                            strText2 = "<a href=\"proinfo_" + myDs.Tables[0].Rows[intCurr + 1]["ID"].ToString() + ".html\">后一篇：" + myDs.Tables[0].Rows[intCurr + 1]["ProName"].ToString() + "</a>";

                        myDs.Dispose();

                        strResult = strText1 + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + strText2;
                    }
                }
            }

            //显示产品窗口
            if (strType == "nextproen")
            {
                if (FunctionClass.CheckStr(strID, 1) && FunctionClass.CheckStr(strTypeID, 1))
                {
                    if (strTypeID == "0" || strTypeID == "")
                    { }
                    else
                    {
                        string strText1, strText2;

                        DataSet myDs = myData.GetDataSet("select * from T_Products where TypeID=" + strTypeID + " order by sid,id desc", myConn);
                        int intCurr = 0;

                        for (int i = 0; i < myDs.Tables[0].Rows.Count; i++)
                        {
                            if (myDs.Tables[0].Rows[i]["ID"].ToString() == strID)
                            {
                                intCurr = i;
                                break;
                            }
                        }

                        if (intCurr - 1 < 0)
                            strText1 = "·Previous：null!";
                        else
                            strText1 = "<a href=\"proinfo_" + myDs.Tables[0].Rows[intCurr - 1]["ID"].ToString() + ".html\">Previous：" + myDs.Tables[0].Rows[intCurr - 1]["ProName"].ToString() + "</a>";
                        if (intCurr + 1 >= myDs.Tables[0].Rows.Count)
                            strText2 = "·Next：null!";
                        else
                            strText2 = "<a href=\"proinfo_" + myDs.Tables[0].Rows[intCurr + 1]["ID"].ToString() + ".html\">Next：" + myDs.Tables[0].Rows[intCurr + 1]["ProName"].ToString() + "</a>";

                        myDs.Dispose();

                        strResult = strText1 + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + strText2;
                    }
                }
            }

            //显示产品子分类
            if (strType == "subprotype")
            {
                strSql = "select * from T_ProType where IsShow=1 and PID=12 order by SID,id";
                SqlDataReader myDr = myData.GetSqlDataReader(strSql, myConn);
                while (myDr.Read())
                {
                    strResult += "<a href='products_products_" + myDr["ID"].ToString() + "_1.html'>· " + myDr["TypeCalled"].ToString() + "</a><br/>";
                }
                myDr.Close();
                myDr.Dispose();
            }

            Response.Write("document.write(\"" + strResult.Replace("\"", "\\\"") + "\");");

            myData.ConnClose(myConn);

            Response.End();
        }
    }
}